package com.ucode.model.hrm.form;


import cn.hutool.core.util.ObjUtil;
import com.ucode.model.hrm.enums.HrmClockType;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.Schema.RequiredMode;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;


@Schema(description = "人力资源系统 - 打卡记录创建Form")
@Data
@EqualsAndHashCode
public class HrmAttendanceRecordCreateForm {

    @Schema(description = "打开日期", requiredMode = RequiredMode.REQUIRED)
    @NotNull(message = "打开日期不能为空")
    private LocalDate workDate;

    @Schema(description = "打卡类型：CLOCK_IN(上班)/CLOCK_OUT(下班)", requiredMode = RequiredMode.REQUIRED, example = "CLOCK_IN")
    @NotBlank(message = "打卡类型不能为空")
    private String clockType;

    /**
     * 打卡纬度
     */
    @Schema(description = "打卡纬度", requiredMode = RequiredMode.REQUIRED)
    @NotNull(message = "打卡纬度不能为空")
    private BigDecimal lat;
    /**
     * 打卡经度
     */
    @Schema(description = "打卡经度", requiredMode = RequiredMode.REQUIRED)
    @NotNull(message = "打卡经度不能为空")
    private BigDecimal lng;
    /**
     * 打卡位置描述
     */
    @Schema(description = "打卡位置", requiredMode = RequiredMode.REQUIRED)
    @NotBlank(message = "打卡位置不能为空")
    private String location;
    /**
     * 打卡备注
     */
    @Schema(description = "打卡备注", requiredMode = RequiredMode.AUTO)
    @Size(max = 255, message = "打卡备注长度不能超过255")
    private String remark;
    /**
     *  图片
     */
    @Schema(description = "图片", requiredMode = RequiredMode.AUTO)
    @Size(max = 3, message = "图片长度不能超过3张")
    private List<String> images;

    @AssertTrue(message = "打卡类型参数范围不正确")
    public boolean isClockTypeIntervalCheck() {
        if(ObjUtil.equals(HrmClockType.CLOCK_IN,clockType) || ObjUtil.equals(HrmClockType.CLOCK_OUT,clockType)){
            return false;
        }
        return true;
    }

}
